App.require(function () {
    var app = App.getCurrent();
    var toastList = [];

    app.definePopUp("strtoast", {
        startEnter: function () {
            console.log("startEnter");
        },
        startToHidden: function () {
            var that = this;
            setTimeout(function () {
                that.hidden();
            }, this.data.timeout || ( this.data.backstr ? 5000 : 2000));
        },
        setCurrentData: function () {
            return this.data;
        },
        beforeShow: function () {
            if (document.activeElement) document.activeElement.blur();
            this.attachDiyEvent("cancel", this.cancelHandler);
            if (!this.data.isNow) toastList.push(this);
            else toastList.unshift(this);
            if (toastList.length == 1) return true;
            return false;
        },
        exitEnd: function (ev) {
            var index = toastList.indexOf(this);
            if (index !== -1) {
                toastList.splice(index, 1);
            }
            if (toastList[0]) app._showPopUp(toastList[0], toastList[0].data, true, true);

            console.log("exitEnd");
        },
        cancelHandler: function () {
            var page = app.getActivePage(this.data.pagename);
            if (page) {
                page.dispatchEvent("toastcancel", {
                    mark: this.data.mark,
                    popUp: this
                });
            }
            else {
                this.hidden();
            }
        }
    })
});